package com.spr.validation;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.spr.model.Faculty;


@Component
public class FacultyValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return Faculty.class.isAssignableFrom(clazz);
		
	}

	@Override
	public void validate(Object target, Errors errors) {
        Faculty faculty = (Faculty) target;
        
        Integer facultyNumber = faculty.getFacultyID();
        
        ValidationUtils.rejectIfEmpty(errors, "firstName", "faculty.firstName.empty");
        ValidationUtils.rejectIfEmpty(errors, "lastName", "faculty.lastName.empty");
        ValidationUtils.rejectIfEmpty(errors, "email", "faculty.email.empty");
        ValidationUtils.rejectIfEmpty(errors, "dateOfBirth", "faculty.dateOfBirth.empty");
        ValidationUtils.rejectIfEmpty(errors, "gender", "faculty.gender.empty");
        ValidationUtils.rejectIfEmpty(errors, "department", "faculty.department.empty");
        ValidationUtils.rejectIfEmpty(errors, "title", "faculty.title.empty");
	}
}
